﻿SET QUOTED_IDENTIFIER ON
GO
SET ARITHABORT ON
GO
SET NUMERIC_ROUNDABORT OFF
GO
SET CONCAT_NULL_YIELDS_NULL ON
GO
SET ANSI_NULLS ON
GO
SET ANSI_PADDING ON
GO
SET ANSI_WARNINGS ON
GO
CREATE TABLE dbo.Tmp_bht_ValidateColumnValidators
	(
	ValidatorId int NOT NULL IDENTITY (1, 1),
	InstanceClass nvarchar(200) NOT NULL,
	ExampleConfiguration nvarchar(MAX) NOT NULL
	)  ON [PRIMARY]
	 TEXTIMAGE_ON [PRIMARY]
GO
ALTER TABLE dbo.Tmp_bht_ValidateColumnValidators SET (LOCK_ESCALATION = TABLE)
GO
SET IDENTITY_INSERT dbo.Tmp_bht_ValidateColumnValidators ON
GO
IF EXISTS(SELECT * FROM dbo.bht_ValidateColumnValidators)
	 EXEC('INSERT INTO dbo.Tmp_bht_ValidateColumnValidators (ValidatorId, InstanceClass, ExampleConfiguration)
		SELECT ValidatorId, InstanceClass, CONVERT(nvarchar(MAX), ExampleConfiguration) FROM dbo.bht_ValidateColumnValidators WITH (HOLDLOCK TABLOCKX)')
GO
SET IDENTITY_INSERT dbo.Tmp_bht_ValidateColumnValidators OFF
GO
ALTER TABLE dbo.bht_ValidateColumnValidatorConfig
	DROP CONSTRAINT FK_bht_ValidateColumnValidatorConfig_bht_ValidateColumnValidators
GO
DROP TABLE dbo.bht_ValidateColumnValidators
GO
EXECUTE sp_rename N'dbo.Tmp_bht_ValidateColumnValidators', N'bht_ValidateColumnValidators', 'OBJECT' 
GO
ALTER TABLE dbo.bht_ValidateColumnValidators ADD CONSTRAINT
	PK_bht_ValidateColumnValidators PRIMARY KEY CLUSTERED 
	(
	ValidatorId
	) WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]

GO
ALTER TABLE dbo.bht_ValidateColumnValidatorConfig ADD CONSTRAINT
	FK_bht_ValidateColumnValidatorConfig_bht_ValidateColumnValidators FOREIGN KEY
	(
	ValidatorId
	) REFERENCES dbo.bht_ValidateColumnValidators
	(
	ValidatorId
	) ON UPDATE  CASCADE 
	 ON DELETE  CASCADE 
	
GO
ALTER TABLE dbo.bht_ValidateColumnValidatorConfig SET (LOCK_ESCALATION = TABLE)


GO
